package com.easy.neo4j.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.easy.common.util.Result;
import com.easy.neo4j.entry.PowerBike;
import com.easy.neo4j.service.BikeService;
import com.easy.neo4j.statistics.PowerBikeStatistics;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;

/**
 * @Author: CoolPro
 * @Description:
 * @Time: 2024-03-29 15:23
 **/

@RestController
@RequestMapping("/bike")
@CrossOrigin
public class BikeController {
    @Resource
    private BikeService bikeService;

    @RequestMapping(value = "/add",method = RequestMethod.POST,produces = "application/json;charset=UTF-8")
    public Result<String> addBike(@RequestBody String data) {
        JSONObject jsonObject = JSON.parseObject(data);
        return bikeService.addBike(jsonObject.getString("pic"),jsonObject.getString("bikeMode"),jsonObject.getString("platform"),jsonObject.getString("lat"),jsonObject.getString("lng"),jsonObject.getString("bikeId"),jsonObject.getString("cityCode"),jsonObject.getString("mileage"),jsonObject.getString("power"),jsonObject.getString("parkName"));
    }

    @RequestMapping(value ="/del/{bikeno}",method = RequestMethod.GET)
    public Result<String> deleteBike(@PathVariable("bikeno") String bikeno) {
        bikeService.deleteBike(bikeno);
        return Result.success();
    }

    @RequestMapping("/query")
    public Result<List<PowerBike>> detailedQueryOfBicycleInformation(
            @RequestParam(value = "parkName") String parkName ,
            @RequestParam(value = "info",defaultValue = "") String info,
            @RequestParam(value = "platform",defaultValue = "") String platform,
            @RequestParam(value = "startMileage",defaultValue = "0") String startMileage,
            @RequestParam(value = "endMileage",defaultValue = "80") String endMileage
    ) {
        return bikeService.detailedQueryOfBicycleInformation(platform, parkName, info, startMileage, endMileage);
    }

    @GetMapping("/query/platform")
    public Result getPlatformInfo() {
        return bikeService.getPlatformInfo();
    }
}
